home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
cjdates.exe
/
DATES.DOC
< prev
next >
Wrap
Text File
|
1991-07-26
|
39KB
|
897 lines
CRAZY JACK'S DATE ROUTINES
USER'S GUIDE
(c)Copyright 1991 by Crazy Jack
All Rights Reserved
NOTICE
This is NOT Public Domain software! You don't have to pay for it
(except for distribution costs) but it IS copyrighted. You may
not sell or distribute the ZDay and ZDate routines or the various
header, "include", documentation or example files for any charge
beyond what is currently customary for "shareware" distribution,
but you may freely incorporate them into your own software with-
out further charge or royalties. In other words, use Crazy
Jack's Date Routines freely, but don't steal.
Crazy Jack's Date Routines may only be distributed as a single
package containing the following 14 files:
READ.ME Introductory remarks and instructions.
DATES.DOC The User's Guide (this file).
DATES.ASM The Date Routines assembler source.
DATES.LST The assembly listing.
DATES.OBJ The assembled object module.
DATES.PAS The Turbo Pascal unit source code.
DATES.TPU The Turbo Pascal v6.0 compiled unit.
DATES.INC Additional Turbo Pascal source code.
DATES.H C header for date routines.
DATENAMS.C Additional C source code for #including.
DTP.PAS Turbo Pascal date routines demo source code.
DTP.EXE Compiled Turbo Pascal date routines demo.
DTC.C Borland C++ C date routines demo source code.
DTC.EXE C date routines demo, ready-to-run.
If you wish to make changes, go ahead, BUT:
1.) If you distribute the result, it must be done under the
rules described in this notice.
2.) Leave the original copyright notices intact; do not remove
existing material.
3.) Add your own copyright notices where appropriate.
4.) Clearly indicate where you have made changes.
Turbo Pascal, Borland C++ and Paradox are trademarks of Borland
International.
1
CRAZY JACK'S DATE ROUTINES USER'S GUIDE
This material has no warranties, expressed or implied as to suit-
ability for any particular task.
Let's face it, gang, even when it's theoretically possible, it's
usually not practical to test most software exhaustively or to
prove its perfection. Further, as in the case of this software,
assumptions are made that are not true for all possible inputs.
For example, no one knows what kind of calendar may be in use
10000 years from now (if any), and Gregorian dates have no mean-
ing in the period before the Gregorian calendar was adopted. (It
was adopted at different times in different places!) The number
of days between two dates always includes weekends and holidays;
you'll have to determine the number of business days yourself.
And so-on. Only a fool will use any piece of software without
testing it for suitability first. Since you're getting these
routines for distribution charges only, what's your beef? Any-
way, I've included the source code so you can "fix" anything you
don't like (at your own risk, of course).
The code was assembled with the Turbo Assembler v2.5 and works as
I intended with programs written in Borland C++ v1.0 (ANSI C
mode) and Turbo Pascal v6.0 (so far).
SO WHAT GOOD IS IT?
For periods covered by the Gregorian calendar, these routines can
be used to determine the day of the week for a given date, to
convert between Gregorian and Julian dates, to validate Gregorian
dates (Is 2/29/1900 a valid date? No, by the Gregorian 400-year
rule that was NOT a leap year!), to determine the number of days
between two dates, and to find a date some number of days from
another date.
Since there are 36524 or 36525 years per century, by subtracting
a base Day Number from the Day Numbers your dates yield, you can
represent a range of a bit over 179 years in a 16-bit unsigned
integer (Turbo Pascal "word").
By storing your dates as Day Numbers you simplify the comparison,
testing and sorting of dates. By using the Day Number as an in-
dex into a suitably constructed bit table you can determine if a
day is a special date such as a holiday.
The monotonic nature of the Day Numbers eliminates the need for
century break testing, something that will soon be a problem.
2
CRAZY JACK'S DATE ROUTINES USER'S GUIDE
INSTALLATION
TURBO PASCAL:
If you use TP v6.0, just copy DATES.TPU into your TPU library and
DATES.INC into the library where you keep frequently used $In-
clude files. (You DO have such a library, don't you?)
Those of you with other versions will have to compile the TPU for
your version. Place DATES.OBJ and DATES.PAS into the same subdi-
rectory on some drive (your RAM disk is a nice place). Make this
the default drive and subdirectory. Execute your version of TP
and load DATES.PAS. Set up to compile to disk, then compile.
Copy the resulting DATES.TPU into your TPU library. Copy
DATES.INC into your $Includes library, and you're ready to go.
Borland C:
Copy DATES.OBJ into your object library where the linker can find
it. Copy DATES.H into your header library, and copy DATENAMS.C
into your #include library.
THE MECHANICS OF USE
TURBO PASCAL:
You'll need a "uses" statement that calls out "Dates" so the
DATES.TPU will be accessed. If you need the additional routines
in DATES.INC, you can use either a {$I dates.inc} statement some-
where before you use the routines. Or copy DATES.INC into your
source code and remove the routines you don't need, or alter them
to suit; for example, you might change day and month names to all
upper case, or change the month and weekday names to another
language.
Borland C:
Put a #include statement for "dates.h" in the front of each mo-
dule in which you use date routines. If you are using DOW() or
MonthName(), remember to #include or copy (and alter to suit
yourself) DATENAMS.C into one of the modules so the code will get
compiled somewhere. YDay() is defined as a macro in DATES.H, and
DATES.OBJ supplies the code for ZDay() and ZDate(). You must put
an entry for DATES.OBJ in your project file, or in your make
file's link command or response file, or wherever is needed so it
will be linked.
3
CRAZY JACK'S DATE ROUTINES USER'S GUIDE
USING ZDAY AND ZDATE
These are the routines for converting Gregorian dates to and from
Day Numbers. They are called using the PASCAL calling sequence,
and are FAR calls. All pointers are FAR pointers.
They can be used with both Borland C and Turbo Pascal programs.
The header file DATES.H defines the interface for Borlan